<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');
?>
<?
      if (isset($_SESSION['k_username'])) {
echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />";
echo "<title >Socios</title>";
echo "<style type=\"text/css\">";
?>
<!--
.Estilo1 {font-size: 24px}
-->
</style>
<title >Socios</title>
<link rel="stylesheet" href="../../css/style1.css" type="text/css" />
<link rel="stylesheet" type="text/css" media="all" href="../../calendario/calendar-green.css" title="win2k-cold-1" /> 
 <!-- librería principal del calendario -->
 <script type="text/javascript" src="../../calendario/calendar.js"></script>

 <!-- librería para cargar el lenguaje deseado -->
  <script type="text/javascript" src="../../calendario/lang/calendar-es.js"></script>

  <!-- librería que declara la función Calendar.setup, que ayuda a generar un calendario en unas pocas líneas de código -->
  <script type="text/javascript" src="../../calendario/calendar-setup.js"></script>    
<script type="text/javascript"  src="../../js/funciones.js"></script>


</head>
<body>
<?php
  include('../../conexion.inc.php');
  $link = Conectarse();

mysql_select_db("gotica_sociosgotica" ,$link);

?>
<div align="center" class="Estilo1" >LISTA SOCIOS</div>
<form method="post" action="buscadorsocio.php">
<table>
<tr>
<?php
if ($_POST['campo']<=4){
$num= $_POST['campo'];}else
{$ese=$_POST['campo']-4;
	$num=5;}

$sql1 = "SELECT * FROM tipocampo ORDER BY tipocampo";
$result1 = mysql_query($sql1, $link);
echo "<td><select name=\"campo\" />";

while ($row1 = mysql_fetch_array($result1))
{
echo "<option value=\"".$row1['idtipocampo']."\">";
echo utf8_encode($row1['tipocampo']);
echo "</option>";
}
echo "</select></td>";
?>
<td>
<input type="text" name="busqueda" value="Buscar..." onFocus="javascript:this.value='';" onBlur="javascript:document.search_form.reset();" />
</td>
<td>
<input type="image" src="/imagenes/viewmag.png" style="border:0px;margin-left:10px;margin-right:3px;" align="absmiddle" value="Buscar" name="busca" />
</td>
</tr>
</table>

</form>
<? if($_SESSION['grupo']==1 || $_SESSION['grupo']==3){ ?>
<form method="post" action="buscadorsocio.php">
<table>
<tr>
<?php 
$sqlt = "SELECT * FROM tiposocio";
$resultt = mysql_query($sqlt, $link);
echo "<td><select name=\"campo\" />";

while ($rowt = mysql_fetch_array($resultt))
{
	$de=$rowt['idTipoSocio']+4;
echo "<option value=\"".$de."\">";
echo $rowt['TipoSocio'];
echo "</option>";
}
echo "</select></td>";

?>
<td>
<input type="submit" value="Elegir Tipo" name="buscatipo" />
</td>
</tr>
<?} ?>
</table>

</form>
<?php 
if($_SESSION['grupo']==1){
echo "<form method=\"post\" action=\"../../exportexcel.php\">";
echo "<table><tr><td>";
echo "<input type=\"hidden\" name=\"num\" value=".$num." />";
echo "<input type=\"hidden\" name=\"busqueda\" value=".$busqueda." />";
echo "<input type=\"hidden\" name=\"ese\" value=".$ese." />";
echo "<input type=\"submit\" value=\"Exportar a Excel\" />";
echo "</td></tr></table>";
echo "</form>";
}
?>
<table width="100%" border="0" cellspacing="2" cellpadding="2" align="center" >
<tr align="center" class="dataheader">
<td></td>
<td></td>
<td>Nº</td>
<td>Nombres</td>
<td>Apellidos</td>
<td>DNI</td>
<td>Direccion</td>
<td>Email</td>
<td>Distrito</td>
<td>Clase</td>
<td>Tipo Socio</td>
<td>Fecha Ingreso</td>
<td>Pago</td>
<td>Fecha Nacimiento</td>
<td>Telefono</td>
<td>Celular</td>
<td>Sexo</td>
<td>Modificado Por</td>
<td>Fecha Modificacion</td>

</tr>
<?php
$busqueda=$_POST['busqueda'];
$busqueda=strtolower($busqueda);
switch ($num){
case 1:
$sql = "SELECT * FROM socios WHERE LCASE(Nombres) LIKE '$busqueda%' ORDER BY Nombres ASC, ApPaterno ASC, ApMaterno ASC " ;
break;
case 2:
$sql = "SELECT * FROM socios WHERE DNI LIKE '$busqueda%' ORDER BY Nombres ASC, ApPaterno ASC, ApMaterno ASC" ;
break;
case 4:
$sql = "SELECT * FROM socios WHERE LCASE(ApPaterno) LIKE  '$busqueda%' OR LCASE(ApMaterno) LIKE  '%$busqueda%' ORDER BY Nombres, ApPaterno, ApMaterno ASC";
break;
case 5:
$sql = "SELECT socios.* FROM socio_tiposocio , socios WHERE ( (socios.idsocio= socio_tiposocio.idsocio) AND (socio_tiposocio.idtiposocio=".$ese.") ) ORDER BY Nombres ASC, ApPaterno ASC, ApMaterno ASC";
break;

case 3:
$sql = "SELECT * FROM socios WHERE FechaNacimiento LIKE  '%$busqueda%' ORDER BY Nombres ASC, ApPaterno ASC, ApMaterno ASC";
break;
default:
$sql = "SELECT * FROM socios ORDER BY Nombres ASC, ApPaterno ASC, ApMaterno ASC";
echo $num;
break;
}
$result = mysql_query($sql, $link);
$cont=0;
while ($row = mysql_fetch_array($result))
{
	$cont++;
echo"<tr align=\"center\" class=\"data\">";
echo "<form method=\"post\" action=\"borrasocio.php\">";
echo "<input type=\"hidden\" value=".$row['idsocio']." name=\"valor\" />";
echo "<input type=\"hidden\" value=0 name=\"page\" />";
echo "<td><input type=\"submit\" class=\"buttonmi\" name=\"borrar\" value=\"Borrar\" /></td>";
echo "</form>";
echo "<form method=\"post\" action=\"edicionsocio.php\">";
echo "<input type=\"hidden\" value=".$row['idsocio']." name=\"valor\" />";
echo "<input type=\"hidden\" value=0 name=\"page\" />";
echo "<td><input type=\"submit\" class=\"buttonmi\" name=\"edit\" value=\"Editar\" /></td>";
echo "</form>";
echo "<td>".$cont."</td>";
echo "<td>".$row['Nombres']."</td>";
echo "<td>".$row['ApPaterno']." ".$row['ApMaterno']."</td>";
echo "<td>".$row['DNI']."</td>";
echo "<td>".$row['Direccion']."</td>";
echo "<td>".$row['Email']."</td>";
$sql2= "Select Distrito FROM distrito where IdDistrit=".$row['IdDistrito'];
$result2 = mysql_query($sql2, $link);
$row2= mysql_fetch_array($result2);
echo "<td>".$row2['Distrito']."</td><td><table>";

$sqlst1= "Select * FROM socio_tiposocio where idsocio=".$row['idsocio'];
$resultst1 = mysql_query($sqlst1, $link);
while($rowst1= mysql_fetch_array($resultst1)){

$sql3= "Select * FROM clase where IdClase=".$rowst1['IdClase'];
$result3 = mysql_query($sql3, $link);
$row3= mysql_fetch_array($result3);
echo "<tr><td>".$row3['Clase']."</td></tr>";
}
echo "</table></td><td><table>";
$sqlst= "Select * FROM socio_tiposocio where idsocio=".$row['idsocio'];
$resultst = mysql_query($sqlst, $link);
while($rowst= mysql_fetch_array($resultst)){
echo "<tr><td>";
$sql4= "Select TipoSocio FROM tiposocio where idTipoSocio=".$rowst['idtiposocio'];
$result4 = mysql_query($sql4, $link);
$row4= mysql_fetch_array($result4);
echo $row4['TipoSocio']."\n" ;
echo "</td></tr>";
  }
echo "</table></td><td>";
$resultst1 = mysql_query($sqlst, $link);
while($rowst1= mysql_fetch_array($resultst1)){
echo $rowst1['FechaIngreso']."\n" ;
  }
echo "</td><td>";
$resultst2 = mysql_query($sqlst, $link);
while($rowst2= mysql_fetch_array($resultst2)){
$sql41= "Select * FROM moneda where idmoneda=".$rowst2['idmoneda'];
$result41 = mysql_query($sql41, $link);
$row41= mysql_fetch_array($result41);
echo $row41['tagmon']." ".$rowst2['pago']."\n" ;
  }
echo "</td>";  

echo "<td>".$row['FechaNacimiento']."</td>";
echo "<td>".$row['Telefono']."</td>";
echo "<td>".$row['Celular']."</td>";
echo "<td>".$row['IdSexo']."</td>";
echo "<td>".$row['editadopor']."</td>";
echo "<td>".$row['edicion']."</td>";
echo"</tr>";
}
?>
</table>

</body>
</html>
<?
}else
{
	echo "<SCRIPT LANGUAGE=\"javascript\">";
echo "location.href = \"index.php\"";
echo "</SCRIPT>";
	}
?>
